﻿mediator = require 'mediator'
CollectionView = require './../collection_view'

module.exports = class MyListView extends CollectionView

	getSelectedItemEventName:->
	clickedItemInternalEventName:null

	lastSelectedItem=null;

	initialize: ->
		@subscribeToControlsEvents();
		super

	subscribeToControlsEvents:->
		@unsubscribeEvent @clickedItemInternalEventName, @raiseSelectedItemChanged
		@subscribeEvent @clickedItemInternalEventName, @raiseSelectedItemChanged

	getView: (view) ->
		#TODO:cast to mylist view
		#view.parent=@
		view.render()
		view.SetSelectedItemChangedEventName @clickedItemInternalEventName
		view

	#ensures is only published if changed
	raiseSelectedItemChanged: (model)->
		if lastSelectedItem==null or lastSelectedItem.id != model.id
			mediator.publish @getSelectedItemEventName(), model
		lastSelectedItem = model


